package com.danjinwulian.web.controller.iot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.danjinwulian.common.core.domain.entity.IotTenant;
import com.danjinwulian.device.service.IIotTenantService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danjinwulian.common.annotation.Log;
import com.danjinwulian.common.core.controller.BaseController;
import com.danjinwulian.common.core.domain.AjaxResult;
import com.danjinwulian.common.enums.BusinessType;
import com.danjinwulian.common.utils.poi.ExcelUtil;
import com.danjinwulian.common.core.page.TableDataInfo;

/**
 * 住客Controller
 * 
 * @author ken.h
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/device/tenant")
public class IotTenantController extends BaseController
{
    @Autowired
    private IIotTenantService iotTenantService;

    /**
     * 查询住客列表
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotTenant iotTenant)
    {
        startPage();
        List<IotTenant> list = iotTenantService.selectIotTenantList(iotTenant);
        return getDataTable(list);
    }

    /**
     * 导出住客列表
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:export')")
    @Log(title = "住客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotTenant iotTenant)
    {
        List<IotTenant> list = iotTenantService.selectIotTenantList(iotTenant);
        ExcelUtil<IotTenant> util = new ExcelUtil<IotTenant>(IotTenant.class);
        util.exportExcel(response, list, "住客数据");
    }

    /**
     * 获取住客详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") Long tenantId)
    {
        return AjaxResult.success(iotTenantService.selectIotTenantByTenantId(tenantId));
    }

    /**
     * 新增住客
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:add')")
    @Log(title = "住客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotTenant iotTenant)
    {
        return toAjax(iotTenantService.insertIotTenant(iotTenant));
    }

    /**
     * 修改住客
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:edit')")
    @Log(title = "住客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotTenant iotTenant)
    {
        return toAjax(iotTenantService.updateIotTenant(iotTenant));
    }

    /**
     * 删除住客
     */
    @PreAuthorize("@ss.hasPermi('device:tenant:remove')")
    @Log(title = "住客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable Long[] tenantIds)
    {
        return toAjax(iotTenantService.deleteIotTenantByTenantIds(tenantIds));
    }
}
